<template>
  <div>
      <el-page-header @back="goBack"></el-page-header>
    <div>
      <span style="margin-left: 570px;font-size: 30px">安全检查记录及整改</span>
      <el-divider content-position="right"></el-divider>
      <div style="width: 1300px">
        <span style="font-size:20px;color: red">基本信息</span>
        <el-form ref="form" label-width="200px" :model="securitycheckrecordForm">
          <el-row>
            <el-col :span="12">
              <el-form-item label="日期:">
                <el-col :span="11">
                  <el-date-picker
                    type="date"
                    placeholder="选择日期"
                    style="width: 450px;"
                    value-format="yyyy-MM-dd"
                     v-model="securitycheckrecordForm.updateDate"
                  ></el-date-picker>
                </el-col>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="安检编号:" required>
                 <el-input disabled placeholder="保存后自动生成"></el-input>
                <!-- <el-select v-model="securitycheckrecordForm.id" style="width: 450px;">
                  <el-option label="--请选择--" value></el-option>
                  <el-option
                    v-for="item in securitycheck"
                    :key="item.id"
                    :label="item.id"
                    :value="item.id"
                  ></el-option>
                </el-select> -->
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目名称:" required>
                <input type="hidden" v-model="securitycheckrecordForm.pid"/>
                     <el-input v-model="securitycheckrecordForm.projectName" @focus="pid" clearable></el-input>
                 <!-- <el-select v-model="securitycheckrecordForm.pid" style="width: 450px;">
                  <el-option label="--请选择--" value></el-option>
                  <el-option
                    v-for="item in projectname"
                    :key="item.id"
                    :label="item.projectName"
                    :value="item.id"
                  ></el-option>
                </el-select> -->
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工程规模:">
                <el-input v-model="securitycheckrecordForm.buildScale"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="形象进度:">
                <el-input v-model="securitycheckrecordForm.progress"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="检查人:" required>
                <el-input v-model="securitycheckrecordForm.checker"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="基本情况:">
              <el-input type="textarea" v-model="securitycheckrecordForm.basicSituation"></el-input>
            </el-form-item>
          </el-row>
            <el-row>
            <el-form-item label="现场检查情况:" required>
              <el-input type="textarea" v-model="securitycheckrecordForm.sceneCheckSituation"></el-input>
            </el-form-item>
          </el-row>
            <el-row>
            <el-form-item label="处理要求及措施:" required>
              <el-input type="textarea" v-model="securitycheckrecordForm.handleMeasure"></el-input>
            </el-form-item>
          </el-row>
            <el-row>
            <el-form-item label="复查情况:">
              <el-input type="textarea" v-model="securitycheckrecordForm.recheckSituation"></el-input>
            </el-form-item>
          </el-row>
            <el-row>
            <el-form-item label="复查人签字:">
              <el-input type="textarea" v-model="securitycheckrecordForm.recheckSignature"></el-input>
            </el-form-item>
          </el-row>
          
              <multi-file-upload
            style="font-size:20px;color: red"
            title="附件"
            action="http://localhost/uploads"
            :params="{folder: 'securitylog'}"
            :headers="{token: token}"
            :show-button="!checkRoute"
            @uploadSuccess="handleUploadSuccess"
            :parent-file-list="fileList"
          ></multi-file-upload>

          <el-form-item>
            <el-button type="primary" style="margin-left: 1000px" @click="addsecuritycheckrecord">确认提交</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <!--所属项目子组件-->
    <el-dialog :visible.sync="dialogVisible" width="50%">
      <project-info-list v-if="dialogVisible" @row="project"></project-info-list>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import { DateUtil } from '../../../model/common/DateUtil';
import ProjectInfoList from '../../common/projectInfo/ProjectInfoList.vue';
export default {
  components: { ProjectInfoList },
  data() {
    return {
       dialogVisible: false, //隐藏子组件
      securitycheckrecordForm: {
        updateDate: DateUtil.today(),
      },
      securitycheck:[],
      projectname:[],
      fileList: [],
       projectId: "" //所属项目id
    };
  },
  methods: {
       //开启隐藏项目子组件
    pid() {
      this.dialogVisible = true;
    },
    //响应项目组件
    project(row) {
      this.securitycheckrecordForm.pid = row.id;
       this.securitycheckrecordForm.projectName = row.projectName;
      this.projectId = row.id; //获取所属项目id
      this.dialogVisible = false;
    },
      goBack() {
      history.back();
    },
  handleUploadSuccess(ids) {
       this.securitycheckrecordForm.attachIds=ids
    },
      //查询安全记录检查编号并渲染下拉框
    SecurityCheckList() {
      axios
        .get(`http://localhost/SecurityCheck`, {
          params: this.securitycheckfrom
        })
        .then(response => {
          this.securitycheck = response.data.data;
        });
    },
     //查询项目名称并渲染到下拉框
    ProjectNameList() {
      axios.get(`http://localhost/SecurityLog/ProjectName`).then(response => {
        this.projectname = response.data.data;
      });
    },
     //添加安全检查记录信息
    addsecuritycheckrecord() {
          if(this.securitycheckrecordForm.pid == '' || this.securitycheckrecordForm.pid == undefined){
            this.$message.error('项目名称不能为空');
          }else {if(this.securitycheckrecordForm.checker == '' || this.securitycheckrecordForm.checker == undefined){
            this.$message.error('检查人不能为空');
          }else {if(this.securitycheckrecordForm.sceneCheckSituation == '' || this.securitycheckrecordForm.sceneCheckSituation == undefined){
            this.$message.error('现场检查情况不能为空');
          }else {if(this.securitycheckrecordForm.handleMeasure == '' || this.securitycheckrecordForm.handleMeasure == undefined){
            this.$message.error('处理要求及措施不能为空');
          }else{
            axios
        .post("http://localhost/SecurityCheck/addsecuritycheck", this.securitycheckrecordForm)
        .then(() => {
          this.$message("添加成功");
          this.$router.push({path:'/SecurityCheckRecordList'})
          this.securitycheckrecordForm = {};
        });
          }
          }
          }
          }
  },
  },
  created() {
    this.SecurityCheckList();
    this.ProjectNameList();
  },
   computed: {
        token: {
                get() {
                    return this.$store.state.token
                }
            },
            checkRoute(){
                return Object.keys(this.$route.params).length != 0
            }
        },
};
</script>

<style>
</style>